package main

import (
	"fabric-go-deploy/common"
	"fmt"

	"github.com/spf13/viper"
)

func main() {
	viper.AddConfigPath("./configs")
	viper.SetConfigType("yaml")
	viper.SetConfigName("config")
	if err := viper.ReadInConfig(); err != nil {
		panic(fmt.Sprintf("ERROR: try to read config file failed, error:%v", err))
	}
	var server []common.Server
	viper.UnmarshalKey("Address", &server)
	fmt.Printf("%+v\n", server)

	var orderer common.OrdererOrg
	viper.UnmarshalKey("OrdererOrgs", &orderer)
	fmt.Printf("%+v\n", orderer)

	var peer []common.PeerOrg
	viper.UnmarshalKey("PeerOrgs", &peer)
	fmt.Println(peer)

	var channel []common.Channel
	viper.UnmarshalKey("Channels", &channel)
	fmt.Println(channel)

	type NewStruct struct {
		First common.OrdererOrg
		Str   string
	}
	haha := NewStruct{
		First: orderer,
		Str:   "&Org22",
	}
	//cc:=json.Marshal(haha)
	viper.Set("OrdererOrgs", haha)

	viper.SafeWriteConfigAs("./test.yaml")
}
